package com.daotingli.backendprograms.DB;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.sql.Connection;
@Component
public class SpringDB {
    @Autowired
    private DataSource  dataSource;
    public DataSource getDataSource() {
        return dataSource;
    }
    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }
    public Connection  getConnection() throws Exception {
        return dataSource.getConnection();
    }

    public JdbcTemplate getJdbcTemplate() {
        return new JdbcTemplate(this.getDataSource());
    }
}
